package com.example.tengoos.controller;

import com.example.tengoos.utils.TengOosUtils;
import com.qcloud.cos.model.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <P>
 *     腾讯云oos演示
 * </P>
 * @author 大忽悠
 * @create 2022/3/6 11:54
 */
@Api(tags = "腾讯云oos测试")
@RestController
@RequestMapping("/oos")
public class OosController {
    @ApiOperation("创建桶")
    @PostMapping("/buckets/{bucketName}")
    public Bucket createBucket(@ApiParam("桶名") @PathVariable("bucketName") String bucketName)
    {
       return TengOosUtils.createBucket(bucketName);
    }

    @ApiOperation("删除桶")
    @DeleteMapping("/deletes")
    public void deleteBucket(@ApiParam("桶名")@RequestParam String bucketName)
    {
         TengOosUtils.deleteBucket(bucketName);
    }

    @ApiOperation("列出所有桶")
    @GetMapping("/buckets")
    public List<Bucket> listBuckets()
    {
        return TengOosUtils.listBuckets();
    }

    @ApiOperation("上传本地小文件")
    @PostMapping("/files")
    public PutObjectResult upLoadSmallFile(@ApiParam("文件名")@RequestParam  String localFilePath, @ApiParam("目标文件路径," +
            "folder/picture.jpg，则表示将文件 picture.jpg 上传到 folder 路径下")@RequestParam  String targetFilePath) {
    return TengOosUtils.upLoadSmallFile(localFilePath,targetFilePath);
    }

    @ApiOperation("列出某个目录下的所有文件")
    @GetMapping("/files")
    public List<COSObjectSummary>  listObjects( @RequestParam String directoryPrefix)
    {
        return TengOosUtils.listObjects(directoryPrefix);
    }

    @ApiOperation("下载文件")
    @PostMapping("/downLoad")
    public ObjectMetadata downLoadFile(@ApiParam("文件key,例如: folder/picture.jpg ")@RequestParam String key,@ApiParam("本地目录名")@RequestParam String localTargetFilePath)
    {
        return TengOosUtils.downLoadFile(key,localTargetFilePath);
    }

    @ApiOperation("删除文件")
    @DeleteMapping("/files")
    public void deleteFile(@ApiParam("文件key,例如: folder/picture.jpg")@RequestParam String key)
    {
        TengOosUtils.deleteFile(key);
    }

}
